<?php

class CommonAction extends Action {
	
	// 检测是否存在超管权限
	function _initialize() {
		// 用户权限检查
		if (!$_SESSION [C('SUPER_ADMIN_AUTH_KEY')]) {
			 redirect(PHP_FILE . C('USER_AUTH_GATEWAY'));
		}
		// 获取指定模块的默认值
		$this->rs = D('Admin')->getModuleConf(ACTION_NAME);
	}
	
	// 保存配置
    public function save(){
    	$type = $_POST['type']; 
    	if($type=='common') D('Admin')->updateCurrency($_POST);
    	D('Admin')->saveConfig();
    	redirect($type,2,'保存成功，2秒后跳转');
    }
    
    // 更新所有流程配置库存规格与固定配置一致
    public function updateFlowStorage(){
    	$flow = array('order','loadContainer','instock','sale','preDelivery','delivery','adjust','transfer','stocktake','initStorage');
    	$key = array('color','size','storage_format','mantissa');
    	$flow_to_once = array('color'=>'storage_color','size'=>'storage_size','storage_format'=>'storage_format','mantissa'=>'storage_mantissa');
    	foreach ($flow as $type) {
    		foreach ($key as $value) {M('Config')->where('`key`=\''.$value.'\' and `type`=\''.$type.'\'')->delete();
    			if ($type=='order' && $value=='mantissa') {
    				continue;
    			}
    			$value2 = C($flow_to_once[$value]);
    			if (empty($value2)) {$value2 = 2;}
    			M('Config')->add(array('key'=>$value,'value'=>$value2,'type'=>$type,'type_key'=>1));
    		}
    	}
    	D('Admin')->updateCofig();
    	redirect('once',2,'保存成功，2秒后跳转');
    }
    
}